<template>
	<view>
		<view v-if="userInfo.roleId === 2">
			<u-list>
				<u-list-item v-for="(item, index) in taskList" :key="index">
					<u-cell :title="item.taskName" :label="item.updateTime.replace('T', ' ')"
						:value="parseStatus(item.status)" :arrow="false" @click="toDetail(item.taskId)">
						<template #right-icon>
							<u-badge :isDot="true" type="primary" v-if="item.status === 1"></u-badge>
							<u-badge :isDot="true" type="warning" v-if="item.status === 2"></u-badge>
							<u-badge :isDot="true" type="error" v-if="item.status === 3"></u-badge>
							<u-badge :isDot="true" type="success" v-if="item.status === 4"></u-badge>
						</template>
					</u-cell>
				</u-list-item>
			</u-list>
			<uni-fab :pattern="pattern" :horizontal="horizontal" :vertical="vertical" :direction="direction"
				@fabClick="fabClick"></uni-fab>
		</view>
		<view v-else>
			<u-subsection :list="list" :current="current" @change="sectionChange"></u-subsection>
			<u-list>
				<u-list-item v-for="(item, index) in taskList" :key="index">
					<u-cell :title="item.taskName" :label="item.updateTime.replace('T', ' ')"
						:value="current === 0 ? item.stu.userName : parseStatus(item.status)" :arrow="false" @click="toDetail(item.taskId)">
					</u-cell>
				</u-list-item>
			</u-list>
		</view>
	</view>
</template>

<script>
	import {
		TaskListService
	} from '../../api/task';
	import {
		parseTime
	} from '../../utils';
	import {
		profileService
	} from '../../api/user';
	export default {
		data() {
			return {
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: '#73C4C8',
					iconColor: '#fff'
				},
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'horizontal',
				taskList: [],
				list: [{
						name: '待处理'
					},
					{
						name: '已完成'
					}
				],
				current: 0,
				userInfo: {},
				status: 1
			};
		},
		onLoad() {
			this.getUserInfo()
		},
		onShow() {
			this.getTaskList()
		},
		methods: {
			async getUserInfo() {
				this.userInfo = await profileService()
				uni.setStorageSync("user-profile", this.userInfo)
			},
			fabClick() {
				uni.navigateTo({
					url: '/pages/taskAdd/taskAdd'
				})
			},
			async getTaskList() {
				if(this.userInfo.roleId === 2) {
					this.taskList = await TaskListService()
				} else {
					this.taskList = await TaskListService({status: this.status})
				}
				
			},
			parseStatus(status) {
				if (status === 1) {
					return '待指导老师审核'
				} else if (status === 2) {
					return '待监管人员通过'
				} else if (status === 3) {
					return '驳回'
				} else {
					return '通过'
				}
			},
			toDetail(id) {
				uni.navigateTo({
					url: `/pages/taskDetail/taskDetail?id=${id}`
				})
			},
			sectionChange(index) {
				console.log(index)
				this.current = index;
				this.status = index + 1
				this.getTaskList()
			}
		},
		computed: {

		}
	}
</script>

<style lang="scss">

</style>